import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

class Selected extends StatelessWidget {
  const Selected({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
            onPressed: () async {
              // 检查相机权限状态
              var status = await Permission.camera.status;

              if (status.isGranted) {
                // 权限已授予
                print("相机权限已授予");
              } else {
                // 请求相机权限
                PermissionStatus result = await Permission.camera.request();
                if (result.isGranted) {
                  print("相机权限已授予");
                } else if (result.isDenied) {
                  print("相机权限被拒绝");
                } else if (result.isPermanentlyDenied) {
                  print("相机权限被永久拒绝，请引导用户前往设置中开启");
                }
              }
            },
            child: Text('申请相机权限')),
      ),
    );
  }
}
